<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initSession(){
		Zend_Session::start();
	}
	
	
	private $_acl = null;
	
    protected function _initAutoload() {
        $modelLoader = new Zend_Application_Module_Autoloader(array(
                        'namespace' => '',
                        'basePath' => APPLICATION_PATH.'/modules/default'));
        
       if(Zend_Auth::getInstance()->hasIdentity()){
       		Zend_Registry::set('role', Zend_Auth::getInstance()->getStorage()->read()->QuyenHan);       		
       } else{
       		Zend_Registry::set('role', 'guests');
       }
       
       $this->_acl = new Model_LibraryAcl;
       $this->_auth = Zend_Auth::getInstance();
       
       $fc = Zend_Controller_Front::getInstance();
       $fc->throwExceptions(true);
       $fc->registerPlugin(new Plugin_AccessCheck($this->_acl));
       
       Zend_Registry::set('acl',$this->_acl);     
        return $modelLoader;
    }
		
		function _initViewHelpers() {
			$view = new Zend_View();
			$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
			
			$view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');
			$viewRenderer->setView($view);
			Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
			
			$this->bootstrap('layout');
			$layout = $this->getResource('layout');
			$view = $layout->getView();
		
			//$view->setHelperPath(APPLICATION_PATH.'/helper', '');
			$view->setHelperPath(APPLICATION_PATH.'/helpers', 'Zend_View_Helper');
			ZendX_JQuery::enableView($view);
						
			//$view->doctype('XHTML1_STRICT');
			$view->doctype('HTML5');
			$view->headMeta()->appendHttpEquiv('Content-type', 'text/html;charset=utf-8')
							->appendName('description', 'Using view helpers in Zend_view');
			
			$view->headTitle()->setSeparator(' - ')
				 ->headTitle('( ¯`·.º-:¦:-* Website - MHB - CĐ*-:¦:-º.·´¯) ');
			
			$navContainerConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
			$navContainer = new Zend_Navigation($navContainerConfig);
			$view->navigation($navContainer)->setAcl($this->_acl)->setRole(Zend_Registry::get('role'));
		}
		
		protected function _initLogs(){
			$logger = new Zend_Log();
			$fireBugWriter =new Zend_Log_Writer_Firebug();
			$logger->addWriter($fireBugWriter);
			Zend_Registry::set('logger', $logger);
		}
	
		
		
	}

